﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MINERP.COM;
using MINERP.DAL;
using MINERP.DAL.CommonDAL;
using MINERP.DAL.Statistics;
using MINERP.MODEL.FoundationModel;
using System.Data;

namespace MINERP.BLL.Statistics
{
    public class OutShopBillBLL
    {
        private newSampleYPDBEntities dataBase = null;
        public OutShopBillBLL()
        {
            dataBase = new newSampleYPDBEntities();
        }
        /// <summary>
        /// 获取所有委外工厂
        /// </summary>
        /// <returns></returns>
        public List<OutProcessShop_Info> GetShopList()
        {
            List<OutProcessShop_Info> listOutShop = new List<OutProcessShop_Info>();

            List<OutProcessShop> list = dataBase.OutProcessShop.ToList();
            foreach (OutProcessShop shop in list)
            {
                OutProcessShop_Info info = new OutProcessShop_Info();
                info.OutShopId = shop.OutShopId;
                info.OutShopName = shop.OutShopName;
                listOutShop.Add(info);
            }
            return listOutShop;
        }
        /// <summary>
        /// 获取委外账单主单
        /// </summary>
        /// <param name="inOutShopId"></param>
        /// <param name="inDataFrom"></param>
        /// <param name="inDataTo"></param>
        /// <returns></returns>
        public List<OutShop_Bill_Info> GetBill(int inOutShopId, DateTime inDataFrom, DateTime inDataTo)
        {
            List<OutShop_Bill_Info> listBill = new List<OutShop_Bill_Info>();
            int comPay = (int)OutProcessPayStatus.Complete;
            List<OutShop_Bill> list =
                dataBase.OutShop_Bill.Where(
                    p =>
                    p.OutProcessShop.OutShopId == inOutShopId && p.CreateTime > inDataFrom && p.CreateTime < inDataTo && p.PayStatus != comPay).
                    ToList();
            //List<OutShop_Bill> list =
            //    dataBase.OutShop_Bill.Where(
            //        p =>
            //        p.OutProcessShop.OutShopId == inOutShopId && p.CreateTime > inDataFrom && p.CreateTime < inDataTo).
            //        ToList();
            foreach (OutShop_Bill bill in list)
            {
                OutShop_Bill_Info info = new OutShop_Bill_Info();
                info.BillID = bill.BillID;
                info.BillOrderCode = bill.BillOrderCode;
                info.CreateTime = bill.CreateTime;
                info.CreateUser = bill.CreateUser;
                info.OutShopId = inOutShopId;
                info.OutShopName = dataBase.OutProcessShop.FirstOrDefault(p => p.OutShopId == inOutShopId).OutShopName;
                info.PayStatus = bill.PayStatus;
                info.ProductSratus = bill.ProductSratus;
                info.Summed = bill.Summed;
                info.SummedRecive = bill.SummedRecive;
                info.SummenPay = bill.SummedPay;
                listBill.Add(info);
            }
            return listBill;
        }
        /// <summary>
        /// 获取委外账单主单
        /// </summary>
        /// <param name="inOutShopId"></param>
        /// <param name="inDataFrom"></param>
        /// <param name="inDataTo"></param>
        /// <returns></returns>
        public List<OutShop_Bill_Info> GetBill(int inOutShopId, DateTime inDataFrom, DateTime inDataTo, bool isDisCom)
        {
            List<OutShop_Bill_Info> listBill = new List<OutShop_Bill_Info>();
            int comPay = (int)OutProcessPayStatus.Complete;
            List<OutShop_Bill> list = new List<OutShop_Bill>();
            if (isDisCom)
            {
                list = dataBase.OutShop_Bill.Where(
                    p =>
                    p.OutProcessShop.OutShopId == inOutShopId && p.CreateTime > inDataFrom && p.CreateTime < inDataTo).ToList();
            }
            else
            {
                list = dataBase.OutShop_Bill.Where(
                   p =>
                   p.OutProcessShop.OutShopId == inOutShopId && p.CreateTime > inDataFrom && p.CreateTime < inDataTo &&
                   p.PayStatus != comPay).
                   ToList();
            }
            foreach (OutShop_Bill bill in list)
            {
                OutShop_Bill_Info info = new OutShop_Bill_Info();
                info.BillID = bill.BillID;
                info.BillOrderCode = bill.BillOrderCode;
                info.CreateTime = bill.CreateTime;
                info.CreateUser = bill.CreateUser;
                info.OutShopId = inOutShopId;
                info.OutShopName = dataBase.OutProcessShop.FirstOrDefault(p => p.OutShopId == inOutShopId).OutShopName;
                info.PayStatus = bill.PayStatus;
                info.ProductSratus = bill.ProductSratus;
                info.Summed = bill.Summed;
                info.SummedRecive = bill.SummedRecive;
                info.SummenPay = bill.SummedPay;
                listBill.Add(info);
            }
            return listBill;
        }
        /// <summary>
        /// 获取委外账单主单
        /// </summary>
        /// <param name="inOutShopId"></param>
        /// <param name="inDataFrom"></param>
        /// <param name="inDataTo"></param>
        /// <returns></returns>
        public List<OutShop_Bill_Info> GetBill(int inBiiId, out OutProcessShop_Info outsShopinfo)
        {
            OutShop_Bill bill = dataBase.OutShop_Bill.FirstOrDefault(p => p.BillID == inBiiId);
            bill.OutProcessShopReference.Load();
            OutProcessShop shop = bill.OutProcessShop;
            List<OutShop_Bill_Info> listBill = new List<OutShop_Bill_Info>();
            OutProcessShop_Info shopinfo = new OutProcessShop_Info();
            shopinfo.OutShopId = shop.OutShopId;
            shopinfo.OutShopName = shop.OutShopName;
            OutShop_Bill_Info info = new OutShop_Bill_Info();
            info.BillID = bill.BillID;
            info.BillOrderCode = bill.BillOrderCode;
            info.CreateTime = bill.CreateTime;
            info.CreateUser = bill.CreateUser;
            info.OutShopId = shop.OutShopId;
            info.OutShopName = shop.OutShopName;
            info.PayStatus = bill.PayStatus;
            info.ProductSratus = bill.ProductSratus;
            info.Summed = bill.Summed;
            info.SummedRecive = bill.SummedRecive;
            info.SummenPay = bill.SummedPay;
            outsShopinfo = shopinfo;
            listBill.Add(info);
            return listBill;
        }
        /// <summary>
        /// 获取委外账单明细
        /// </summary>
        /// <param name="inBill"></param>
        /// <returns></returns>
        public List<OutShopBillDetail_Info> GetDetails(int inBill)
        {
            List<OutShopBillDetail_Info> listDetailInfo = new List<OutShopBillDetail_Info>();
            OutShop_Bill bill = dataBase.OutShop_Bill.FirstOrDefault(p => p.BillID == inBill);
            bill.OutShopBillDetail.Load();
            List<OutShopBillDetail> list = bill.OutShopBillDetail.ToList();
            foreach (OutShopBillDetail detail in list)
            {
                OutShopBillDetail_Info info = new OutShopBillDetail_Info();
                info.BillDetailID = detail.BillDetailID;
                info.BillID = inBill;
                info.CtmName = detail.CtmName;
                info.Num = detail.Num;
                info.OrderProductCode = detail.OrderProductCode;
                info.OrderProductName = detail.OrderProductName;
                info.PayStatus = detail.PayStatus;
                info.ProductStatus = detail.ProductStatus;
                info.Spc = detail.Spc;
                info.UnitPrice = detail.UnitPrice;
                info.ProductName = detail.ProductName;
                listDetailInfo.Add(info);
            }
            return listDetailInfo;
        }

        //public void UpdateBill(OutShop_Bill_Info inBill, List<OutShopBillDetail_Info> inlist)
        //{
        //    OutShop_Bill bill = dataBase.OutShop_Bill.FirstOrDefault(p => p.BillID == inBill.BillID);
        //    bill.OutShopBillDetail.Load();
        //    List<OutShopBillDetail> listDetail = bill.OutShopBillDetail.ToList();
        //    foreach (OutShopBillDetail_Info list in inlist)
        //    {

        //    }
        //}
        /// <summary>
        /// 更新账单明细
        /// </summary>
        /// <param name="inBill"></param>
        /// <param name="inDetail"></param>
        public void UpdateBillDetail(int inBillID, OutShopBillDetail_Info inDetail)
        {
            OutShop_Bill bill = dataBase.OutShop_Bill.FirstOrDefault(p => p.BillID == inBillID);
            List<OutShopBillDetail> listDetail = bill.OutShopBillDetail.ToList();
            OutShopBillDetail detail = listDetail.FirstOrDefault(p => p.BillDetailID == inDetail.BillDetailID);

            if (detail != null)//修改
            {
                bill.Summed = bill.Summed - detail.UnitPrice * detail.Num + inDetail.Num * inDetail.UnitPrice;

                detail.CtmName = inDetail.CtmName;
                detail.Num = inDetail.Num;
                detail.OrderProductCode = inDetail.OrderProductCode;
                detail.OrderProductName = inDetail.OrderProductName;
                detail.PayStatus = inDetail.PayStatus;
                detail.ProductStatus = inDetail.ProductStatus;
                detail.Spc = inDetail.Spc;
                detail.UnitPrice = inDetail.UnitPrice;
                //if(listDetail.Where(p=>p.PayStatus==))

            }
            else//新添加一条明细
            {
                bill.Summed = bill.Summed + inDetail.Num * inDetail.UnitPrice;
                detail = new OutShopBillDetail();
                detail.CtmName = inDetail.CtmName;
                detail.Num = inDetail.Num;
                detail.OrderProductCode = inDetail.OrderProductCode;
                detail.OrderProductName = inDetail.OrderProductName;
                detail.PayStatus = inDetail.PayStatus;
                detail.ProductStatus = inDetail.ProductStatus;
                detail.Spc = inDetail.Spc;
                detail.UnitPrice = inDetail.UnitPrice;
                listDetail.Add(detail);
                detail.OutShop_Bill = bill;


            }


            int payAll = (int)OutProcessPayStatus.Complete;
            int productRecevie = (int)OutProcessProductStatus.Received;
            ;


            bill.SummedRecive = listDetail.Where(p => p.ProductStatus == productRecevie).Sum(p => p.UnitPrice * p.Num);

            int payAction = listDetail.Count(p => p.PayStatus == payAll);
            int prodrctAction = listDetail.Count(p => p.ProductStatus == productRecevie);
            int intCountAll = listDetail.Count();
            if (payAction == 0)
            {
                bill.PayStatus = (int)OutProcessPayStatus.UnPay;
            }
            else if (payAction > 0 && payAction < intCountAll)
            {
                bill.PayStatus = (int)OutProcessPayStatus.Part;
            }
            else
            {
                bill.PayStatus = (int)OutProcessPayStatus.Complete;
            }
            if (prodrctAction == 0)
            {
                bill.ProductSratus = (int)OutProcessProductStatus.Outting;
            }
            else if (prodrctAction > 0 && prodrctAction < intCountAll)
            {
                bill.ProductSratus = (int)OutProcessProductStatus.Received;
            }
            else
            {
                bill.ProductSratus = (int)OutProcessProductStatus.Complete;
            }
            dataBase.SaveChanges();


        }
        public void DeleteDetail(OutShopBillDetail_Info inDetail)
        {
            OutShopBillDetail delObj = dataBase.OutShopBillDetail.FirstOrDefault(p => p.BillDetailID == inDetail.BillDetailID);
            dataBase.DeleteObject(delObj);
            dataBase.SaveChanges();
        }

        public void CrushOutshop(List<OutShop_Bill_Info> inBillList, decimal inMoney, decimal inChange, string inRemark, int inUserId, int inOutShopId)
        {
            foreach (OutShop_Bill_Info billInfo in inBillList)
            {
                OutShop_Bill bill = dataBase.OutShop_Bill.FirstOrDefault(p => p.BillID == billInfo.BillID);
                bill.OutShopBillDetail.Load();
                List<OutShopBillDetail> listDetail = bill.OutShopBillDetail.ToList();
                int payStatus = (int)OutProcessPayStatus.Complete;
                foreach (OutShopBillDetail list in listDetail)
                {
                    if (list.ProductStatus == (int)OutProcessProductStatus.Received)
                    {
                        list.PayStatus = (int)OutProcessPayStatus.Complete;
                    }
                }
                int intPay = listDetail.Count(p => p.PayStatus == payStatus);
                int Count = listDetail.Count;
                if (listDetail.Count == intPay)
                {
                    bill.PayStatus = payStatus;
                }
                else if (intPay > 0 && intPay < Count)
                {
                    bill.PayStatus = (int)OutProcessPayStatus.Part;
                }
                decimal payCout = listDetail.Where(p => p.PayStatus == payStatus).Sum(p => p.Num * p.UnitPrice);
                bill.SummedPay = payCout;


            }

            OutShopBlanceCrushRecord outShopBlanceCrushRecord = new OutShopBlanceCrushRecord();
            outShopBlanceCrushRecord.ChangeMoney = inMoney;
            outShopBlanceCrushRecord.CreateTime = CommonMethodDAL.GetServerTime();//获取系统时间
            outShopBlanceCrushRecord.OperateId = inUserId;
            outShopBlanceCrushRecord.OutProcessShop =
                dataBase.OutProcessShop.FirstOrDefault(p => p.OutShopId == inOutShopId);
            outShopBlanceCrushRecord.Remark = inRemark;
            dataBase.AddToOutShopBlanceCrushRecord(outShopBlanceCrushRecord);
            dataBase.SaveChanges();

        }

        /// <summary>
        /// 获取委外账单主单
        /// </summary>
        /// <param name="inOutShopId"></param>
        /// <param name="inDataFrom"></param>
        /// <param name="inDataTo"></param>
        /// <returns></returns>
        public DataSet GetBillTable(int inOutShopId, DateTime inDataFrom, DateTime inDataTo)
        {
            List<OutShop_Bill_Info> listBill = new List<OutShop_Bill_Info>();
            int comPay = (int)OutProcessPayStatus.Complete;
            List<OutShop_Bill> list = dataBase.OutShop_Bill.Where(
                    p =>
                    p.OutProcessShop.OutShopId == inOutShopId && p.CreateTime > inDataFrom && p.CreateTime < inDataTo).ToList();


            DataTable table = CreateBillTable();
            DataTable dataDetailTable = CreateBillDetailTable();
          
            foreach (OutShop_Bill bill in list)
            {
                //region
                #region 创建账单主表
                DataRow row = table.NewRow();
                row["BillID"] = bill.BillID;
                row["BillOrderCode"] = bill.BillOrderCode;
                row["CreateTime"] = bill.CreateTime;
                row["CreateUser"] = bill.CreateUser;
                row["OutShopId"] = inOutShopId;
                row["OutShopName"] = dataBase.OutProcessShop.FirstOrDefault(p => p.OutShopId == inOutShopId).OutShopName;

                switch (bill.PayStatus)
                {
                    case (int)OutProcessPayStatus.UnPay:
                        row["PayStatus"] = "未付款";
                        break;
                    case (int)OutProcessPayStatus.Part:
                        row["PayStatus"] = "部分付款";
                        break;
                    case (int)OutProcessPayStatus.Complete:
                        row["PayStatus"] = "完全付款";
                        break;
                    default:
                        break;

                }
                switch (bill.ProductSratus)
                {
                    case (int)OutProcessProductStatus.Outting:
                        row["ProductSratus"] = "委外中";
                        break;
                    case (int)OutProcessProductStatus.Received:
                        row["ProductSratus"] = "部分收货";
                        break;
                    case (int)OutProcessProductStatus.Complete:
                        row["ProductSratus"] = "完全收货";
                        break;
                    default:
                        break;

                }
                //row["ProductSratus"]= bill.ProductSratus;
                row["Summed"] = bill.Summed;
                row["SummedRecive"] = bill.SummedRecive;
                row["SummenPay"] = bill.SummedPay;

                table.Rows.Add(row);
                #endregion
                bill.OutShopBillDetail.Load();
                List<OutShopBillDetail> listDetail = bill.OutShopBillDetail.ToList();
                foreach (OutShopBillDetail detail in listDetail)
                {
                    DataRow detailRow = dataDetailTable.NewRow();
                    detailRow["BillDetailID"] = detail.BillDetailID;
                    detailRow["BillID"] = bill.BillID;
                    detailRow["CtmName"] = detail.CtmName;
                    detailRow["OrderProductCode"] = detail.OrderProductCode;
                    detailRow["OrderProductName"] = detail.OrderProductName;
                    detailRow["Spc"] = detail.Spc;
                    detailRow["Num"] = detail.Num;
                    detailRow["UnitPrice"] = detail.UnitPrice;
                    detailRow["ProductStatus"] = detail.ProductStatus;

                    switch (detail.ProductStatus)
                    {
                        case (int)OutProcessProductStatus.Outting:
                            detailRow["ProductStatus"] = "委外中";
                            detailRow["ReceiveCount"] = 0;
                            break;
                        case (int)OutProcessProductStatus.Received:
                            detailRow["ProductStatus"] = "已收货";
                            detailRow["ReceiveCount"] = detail.UnitPrice*detail.Num;
                            break;
                        default:
                            break;

                    }
                    switch (detail.PayStatus)
                    {
                        case (int)OutProcessPayStatus.UnPay:
                            detailRow["PayStatus"] = "未付款";
                            detailRow["PayCount"] = 0;
                            break;
                        case (int)OutProcessPayStatus.Complete:
                            detailRow["PayStatus"] = "已付款";
                            detailRow["PayCount"] = detail.UnitPrice * detail.Num;
                            break;
                        default:
                            break;
                    }
                   // detailRow["PayStatus"] = detail.PayStatus;
                    detailRow["Count"] = detail.UnitPrice * detail.Num;
                    
                    dataDetailTable.Rows.Add(detailRow);
                }


            }
            #region 委外商户信息
            OutProcessShop outProcessShop = dataBase.OutProcessShop.FirstOrDefault(p => p.OutShopId == inOutShopId);
            DataTable outShopTable = CreateOutShopTable();

            DataRow outshopRow = outShopTable.NewRow();
            outshopRow["OutShopId"] = outProcessShop.OutShopId;
            outshopRow["OutShopName"] = outProcessShop.OutShopName;
            outshopRow["Keeper"] = outProcessShop.Keeper;
            outshopRow["Tel1"] = outProcessShop.Tel1;
            outshopRow["Tel2"] = outProcessShop.Tel2;
            outshopRow["City"] = outProcessShop.City;
            outshopRow["EmailAddress"] = outProcessShop.EmailAddress;
            outshopRow["Code"] = outProcessShop.Code;      
            outShopTable.Rows.Add(outshopRow);
            outShopTable.TableName = "outShopTable";
            #endregion
            table.TableName = "BillTable";
            dataDetailTable.TableName = "DetailTable";
            DataSet set = new DataSet();
            set.Tables.Add(outShopTable);
            set.Tables.Add(table);
            set.Tables.Add(dataDetailTable);
            return set;
        }

        /// <summary>
        /// 通过产品号获取委外账单主单
        /// </summary>
        /// <param name="inOutShopId"></param>
        /// <param name="inDataFrom"></param>
        /// <param name="inDataTo"></param>
        /// <returns></returns>
        public DataSet GetBillTableByOrderProductCode(string orderProductCode)
        {
            OutShopBillDetail billDatail = dataBase.OutShopBillDetail.FirstOrDefault(o => o.OrderProductCode == orderProductCode);
            if (billDatail == null)
                return null;

            if (!billDatail.OutShop_BillReference.IsLoaded)
            {
                billDatail.OutShop_BillReference.Load();
            }
            OutShop_Bill bill = billDatail.OutShop_Bill;
            if (!bill.OutProcessShopReference.IsLoaded)
            {
                bill.OutProcessShopReference.Load();
            }
            int inOutShopId = bill.OutProcessShop.OutShopId;
            //List<OutShop_Bill_Info> listBill = new List<OutShop_Bill_Info>();
            int comPay = (int)OutProcessPayStatus.Complete;
            //List<OutShop_Bill> list = dataBase.OutShop_Bill.Where(
            //        p =>
            //        p.OutProcessShop.OutShopId == inOutShopId && p.CreateTime > inDataFrom && p.CreateTime < inDataTo).ToList();


            DataTable table = CreateBillTable();
            DataTable dataDetailTable = CreateBillDetailTable();

            //foreach (OutShop_Bill bill in list)
            //{
                //region
                #region 创建账单主表
                DataRow row = table.NewRow();
                row["BillID"] = bill.BillID;
                row["BillOrderCode"] = bill.BillOrderCode;
                row["CreateTime"] = bill.CreateTime;
                row["CreateUser"] = bill.CreateUser;
                row["OutShopId"] = inOutShopId;
                row["OutShopName"] = dataBase.OutProcessShop.FirstOrDefault(p => p.OutShopId == inOutShopId).OutShopName;

                switch (bill.PayStatus)
                {
                    case (int)OutProcessPayStatus.UnPay:
                        row["PayStatus"] = "未付款";
                        break;
                    case (int)OutProcessPayStatus.Part:
                        row["PayStatus"] = "部分付款";
                        break;
                    case (int)OutProcessPayStatus.Complete:
                        row["PayStatus"] = "完全付款";
                        break;
                    default:
                        break;

                }
                switch (bill.ProductSratus)
                {
                    case (int)OutProcessProductStatus.Outting:
                        row["ProductSratus"] = "委外中";
                        break;
                    case (int)OutProcessProductStatus.Received:
                        row["ProductSratus"] = "部分收货";
                        break;
                    case (int)OutProcessProductStatus.Complete:
                        row["ProductSratus"] = "完全收货";
                        break;
                    default:
                        break;

                }
                //row["ProductSratus"]= bill.ProductSratus;
                row["Summed"] = bill.Summed;
                row["SummedRecive"] = bill.SummedRecive;
                row["SummenPay"] = bill.SummedPay;

                table.Rows.Add(row);
                #endregion
                bill.OutShopBillDetail.Load();
                List<OutShopBillDetail> listDetail = bill.OutShopBillDetail.ToList();
                foreach (OutShopBillDetail detail in listDetail)
                {
                    DataRow detailRow = dataDetailTable.NewRow();
                    detailRow["BillDetailID"] = detail.BillDetailID;
                    detailRow["BillID"] = bill.BillID;
                    detailRow["CtmName"] = detail.CtmName;
                    detailRow["OrderProductCode"] = detail.OrderProductCode;
                    detailRow["OrderProductName"] = detail.OrderProductName;
                    detailRow["Spc"] = detail.Spc;
                    detailRow["Num"] = detail.Num;
                    detailRow["UnitPrice"] = detail.UnitPrice;
                    detailRow["ProductStatus"] = detail.ProductStatus;

                    switch (detail.ProductStatus)
                    {
                        case (int)OutProcessProductStatus.Outting:
                            detailRow["ProductStatus"] = "委外中";
                            detailRow["ReceiveCount"] = 0;
                            break;
                        case (int)OutProcessProductStatus.Received:
                            detailRow["ProductStatus"] = "已收货";
                            detailRow["ReceiveCount"] = detail.UnitPrice * detail.Num;
                            break;
                        default:
                            break;

                    }
                    switch (detail.PayStatus)
                    {
                        case (int)OutProcessPayStatus.UnPay:
                            detailRow["PayStatus"] = "未付款";
                            detailRow["PayCount"] = 0;
                            break;
                        case (int)OutProcessPayStatus.Complete:
                            detailRow["PayStatus"] = "已付款";
                            detailRow["PayCount"] = detail.UnitPrice * detail.Num;
                            break;
                        default:
                            break;
                    }
                    // detailRow["PayStatus"] = detail.PayStatus;
                    detailRow["Count"] = detail.UnitPrice * detail.Num;

                    dataDetailTable.Rows.Add(detailRow);
                }


            //}
            #region 委外商户信息
            OutProcessShop outProcessShop = dataBase.OutProcessShop.FirstOrDefault(p => p.OutShopId == inOutShopId);
            DataTable outShopTable = CreateOutShopTable();

            DataRow outshopRow = outShopTable.NewRow();
            outshopRow["OutShopId"] = outProcessShop.OutShopId;
            outshopRow["OutShopName"] = outProcessShop.OutShopName;
            outshopRow["Keeper"] = outProcessShop.Keeper;
            outshopRow["Tel1"] = outProcessShop.Tel1;
            outshopRow["Tel2"] = outProcessShop.Tel2;
            outshopRow["City"] = outProcessShop.City;
            outshopRow["EmailAddress"] = outProcessShop.EmailAddress;
            outshopRow["Code"] = outProcessShop.Code;
            outShopTable.Rows.Add(outshopRow);
            outShopTable.TableName = "outShopTable";
            #endregion
            table.TableName = "BillTable";
            dataDetailTable.TableName = "DetailTable";
            DataSet set = new DataSet();
            set.Tables.Add(outShopTable);
            set.Tables.Add(table);
            set.Tables.Add(dataDetailTable);
            return set;
        }
        /// <summary>
        /// 获取委外产品
        /// </summary>
        /// <param name="inOutShopId"></param>
        /// <param name="inStartTime"></param>
        /// <param name="inEndTime"></param>
        /// <param name="inProductStatus"></param>
        /// <param name="inPayStatus"></param>
        /// <returns></returns>
         public  DataSet GetOutShopProduct(int  inOutShopId, DateTime inStartTime, DateTime inEndTime,int inProductStatus,int inPayStatus)
         {
             OutShopBillDAL _dal=new OutShopBillDAL();
             OutProcessShop outProcessShop = dataBase.OutProcessShop.FirstOrDefault(p => p.OutShopId == inOutShopId);
             DataTable outShopTable = CreateOutShopTable();

             DataRow outshopRow = outShopTable.NewRow();
             outshopRow["OutShopId"] = outProcessShop.OutShopId;
             outshopRow["OutShopName"] = outProcessShop.OutShopName;
             outshopRow["Keeper"] = outProcessShop.Keeper;
             outshopRow["Tel1"] = outProcessShop.Tel1;
             outshopRow["Tel2"] = outProcessShop.Tel2;
             outshopRow["City"] = outProcessShop.City;
             outshopRow["EmailAddress"] = outProcessShop.EmailAddress;
             outshopRow["Code"] = outProcessShop.Code;
             outShopTable.Rows.Add(outshopRow);
             outShopTable.TableName = "outShopTable";
             DataSet set = _dal.GetOutShopProduct(inOutShopId, inStartTime, inEndTime, inProductStatus, inPayStatus);
             set.Tables.Add(outShopTable);
             return set ;
              
         }



        DataTable CreateBillTable()
        {
            DataTable table = new DataTable();
            table.Columns.Add("BillID", typeof(int));
            table.Columns.Add("BillOrderCode", typeof(int));
            table.Columns.Add("CreateTime", typeof(DateTime));
            table.Columns.Add("CreateUser", typeof(string));
            table.Columns.Add("OutShopName", typeof(string));
            table.Columns.Add("OutShopId", typeof(int));
            table.Columns.Add("PayStatus", typeof(string));
            table.Columns.Add("ProductSratus", typeof(string));
            table.Columns.Add("Summed", typeof(decimal));
            table.Columns.Add("SummedRecive", typeof(decimal));
            table.Columns.Add("SummenPay", typeof(decimal));
            return table;
        }
        DataTable CreateOutShopTable()
        {
            DataTable table = new DataTable();
            table.Columns.Add("OutShopId", typeof(int));
            table.Columns.Add("OutShopName", typeof(string));
            table.Columns.Add("Keeper", typeof(string));
            table.Columns.Add("Tel1", typeof(string));
            table.Columns.Add("Tel2", typeof(string));
            table.Columns.Add("City", typeof(string));
            table.Columns.Add("Addr", typeof(string));
            table.Columns.Add("EmailAddress", typeof(string));
            table.Columns.Add("Code", typeof(string));
            return table;

        }

        DataTable CreateBillDetailTable()
        {
            DataTable table = new DataTable();
            table.Columns.Add("BillDetailID", typeof(int));
            table.Columns.Add("BillID", typeof(int));
            table.Columns.Add("CtmName", typeof(string));
            table.Columns.Add("OrderProductCode", typeof(string));
            table.Columns.Add("OrderProductName", typeof(string));
            table.Columns.Add("Spc", typeof(string));
            table.Columns.Add("Num", typeof(int));
            table.Columns.Add("UnitPrice", typeof(decimal));
            table.Columns.Add("ProductStatus", typeof(string));
            table.Columns.Add("PayStatus", typeof(string));
            table.Columns.Add("PayCount", typeof(decimal));
            table.Columns.Add("ReceiveCount", typeof(decimal));
            table.Columns.Add("Count", typeof(decimal));
            return table;
        }
    }





}
